home *** CD-ROM | disk | FTP | other *** search
- unit Setunit;
- { PC Plus simple Delphi sample program. Illustrates the use of Sets
- with integers and chars }
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- ListBox1: TListBox;
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Button1Click(Sender: TObject);
- type { the type MyNumbers defines integers between 0 and 100 }
- MyNumbers = 1..100;
- const
- { the const, Digits, defines a set (effectively a 'subset') of
- MyNumbers between 1 and 10 }
- Digits : set of MyNumbers = [1..10];
- { UpCaseLetters defines a set of chars from 'A' to 'Z' }
- UpCaseLetters : set of char = ['A'..'Z'];
- begin
- { Beware: set constants aren't as constant as they seem. Try
- uncommenting this line and re-running the program. }
- { Digits := [1..20]; }
- { test for set membership using 'in' }
- if 'A' in UpCaseLetters then
- ListBox1.Items.Add('Yes - A is in UpCaseLetters')
- else
- ListBox1.Items.Add('No - A is not in UpCaseLetters');
- if 11 in Digits then
- ListBox1.Items.Add('Yes - 11 is in Digits')
- else
- ListBox1.Items.Add('No - 11 is not in Digits');
-
- end;
-
- end.
-